package homework;
abstract  class  Employee{//定义抽象类Employee，代表员工
    public String name;//员工姓名
    public  double salary;//员工工资
    public  Employee(String name,double salary){//构造函数书，初始化员工姓名和工资
       this.name=name;
        this.salary=salary;
    }
     public abstract   void  calculateSalary();//抽象方法，计算工资
}
class SlariedEmployee extends Employee{//定义月薪员工，继承自Employee类
    public SlariedEmployee(String name,double salary){//构造函数
        super(name, salary);//super调用父类初始化姓名和工资
    }
    public void calculateSalary(){
        System.out.println("name:"+name+"    monthlysalary:"+salary);//复写calculateSalary抽象函数，直接输出月薪员工工资
    }
};
class HourlyEmployee extends Employee{//定义日薪员工，继承自Employee类
    double time;//子类的特殊属性，工作时长
    public  HourlyEmployee(String name,double salary,double time){//构造函数
        super(name, salary);//调用父类的构造函数初始化姓名和工资
        this.time=time;//初始化工作时长
    }
    public void calculateSalary(){//复写calculateSalary抽象方法，实现日薪员工工资计算后输出
        System.out.println("name:"+name+"    Hourlysalary:"+salary*time);
    }
};

public class Salary {
    public static  void main(String []args){
        Employee[]employees=new Employee[3];//创建Employee类型的数字employees，存储不同类型的员工对象
        employees[0]=new SlariedEmployee("李四",10000.9);//创建月薪员工对象，放入数组中第一个元素
        employees[1]=new HourlyEmployee("张三",200,12.5);//创建日薪员工对象，放入数组中第二个元素
        employees[2]=new SlariedEmployee("王五",70009.8);//创建月薪员工对象，放入数组第三个元素

        for(Employee i:employees){// 遍历员工数组，调用每个员工对象的calculateSalary方法来计算并输出工资
            i.calculateSalary();
        }
    }
}
